package com.qs.rocketmq.right.listener;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQReplyListener;
import org.springframework.stereotype.Component;

/**
 * 生产者发送消息需要消费端消费后应答的，需要实现 RocketMQReplyListener 接口
 *
 * @author qinyupeng
 * @since 2021-12-31 16:12:55
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "QS_ORDER_APP_TOPIC", consumerGroup = "QS_ORDER_CONSUMER_GROUP")
public class ConsumerReplayListener implements RocketMQReplyListener<MessageExt, String> {

    // MessageExt 包含消息内容及其附加信息，如果需要获取附加消息，则可以从这里面取
    @Override
    public String onMessage(MessageExt message) {
        String msgContent = StrUtil.str(message.getBody(), "UTF-8");
        log.info("消费者接收消息：{}，tag={}，keys={}，线程：{}", msgContent, message.getTags(), message.getKeys(), Thread.currentThread().getName());
        return "ok";
    }
}
